import { connection } from '../app/database/mysql';
import { tokenCookieModel } from './tokenCookie.model';

/**
 * 获取 token_cookie
 */
export const getTokenCookie = async () => {
  // 准备查询
  const statement = `
    SELECT * FROM token_cookie
  `;

  // 执行查询
  const [data] = await connection.promise().query(statement);

  let res = { data };

  // 提供数据
  return res;
};

/**
 * 更新内容
 */
export const updateTokenCookie = async (post: tokenCookieModel, postId: number) => {
  // 准备查询
  const statement = `
    UPDATE token_cookie
    SET ?
    WHERE id = ?
  `;

  // 执行查询
  const [data] = await connection.promise().query(statement, [post, postId]);

  // 提供数据
  return data;
}
